/**
 * @author:fangxiaohua
*  @邮箱：abc2710712@qq.com
*  @qq:1295168875
*   用户业务操作操作
*/
void(function(exports){
	//数据库操作
	var dbLib = require('../lib/dbLib');
	//工具类模块
	var tools = require('../lib/toolsLib');
	
	//黑名单列表
	exports.list = function(req, res){
		var pageNo=req.body.pageNo;
		var pageSize=req.body.pageSize;
		var q=req.body.q;
		var status=req.body.status;
		var  sql="select u.id,u.account,u.reason from t_user u where u.status=? and (u.account like ? or u.reason like ? )";
		q=q==null?"%%":"%"+q+"%";
		var params=[status,q,q];
		dbLib.dbPageQuery(sql,pageNo,pageSize,params,function(err,result){
			res.send(result);
			return;
		});
	};
	
	//取消黑名单
	exports.cancel = function(req, res){
		var id=req.body.id;
		var status=req.body.status;
		var sql="update t_user f set f.status=? ,f.reason=''  where f.id=?";
		var params=[status,id];
		dbLib.dbUpdate(sql,params,function(err,result){
			if(err){
				res.send("false");
				return;
			}
			res.send("true");
			return;
		});
	};
	
	//用户快速查询
	exports.ulist=function(req,res){
		var q=req.body.q;
		q=q==null?"%%":"%"+q+"%";
		var sql="select u.account as name,u.id from t_user u where u.account like ? limit 0,20";
		var params=[q];
		dbLib.dbQuery(sql,params,function(err,result){
			res.send(result);
			return;
		});
	}
	
	//添加黑名单
	exports.add = function(req, res){
		var id=req.body.id;
		var status=req.body.status;
		var reason=req.body.reason;
		var sql="update t_user f set f.status=?,f.reason=?  where f.id=?";
		var params=[status,reason,id];
		dbLib.dbUpdate(sql,params,function(err,result){
			if(err){
				res.send("false");
				return;
			}
			res.send("true");
			return;
		});
	};
	
	
})( (function(){
    if(typeof exports === 'undefined') {
        window.exports = {};
        return window.exports;
    } else {
        return exports;
    }
})());